package 图.树;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/8/14 22:29
 */
public class lc617合并二叉树 {

    /*
     二叉树的题目还是很有意思的!

     两颗树一块遍历卧槽!
     */


    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
            if(root1 == null){
                return root2;
            }
            if(root2 == null){
                return root1;
            }
            // 走到这 说明 左右 子节点都在
           root1.val += root2.val;
           root1.left = mergeTrees(root1.left,root2.left);
           root1.right = mergeTrees(root1.right,root2.right);
           return root1;
    }




    class TreeNode {
          int val;
          TreeNode left;
          TreeNode right;
          TreeNode() {}
          TreeNode(int val) { this.val = val; }
          TreeNode(int val, TreeNode left, TreeNode right) {
              this.val = val;
              this.left = left;
              this.right = right;
          }
      }

}
